<?php
    $basename=basename($_SERVER['SCRIPT_FILENAME']);
    $username=getsession('username','shop');
    $id=getsession('id','shop');
    if(!empty($username)){
        $prefix=getprefix();
        $sql="SELECT price,quantity,products FROM {$prefix}cart WHERE uid='{$id}'";
        $r=queryone($sql);
        if($r){
            $array=json_decode($r['products'],true);
        }
        
      }  //一定要加true
    

                    

   

    if($basename=='login.php'):
?>
      <!-- Start Cart Panel -->
        <div class="shopping__cart">
            <div class="shopping__cart__inner">
                <div class="offsetmenu__close__btn">
                    <a href="#"><i class="zmdi zmdi-close"></i></a>
                </div>
                <div class="shp__cart__wrap">
                    <div class="shp__single__product">
                        <div class="shp__pro__thumb">
                            <a href="#">
                                <img src="assets/images/product/sm-img/1.jpg" alt="product images">
                            </a>
                        </div>
                        <div class="shp__pro__details">
                            <h2><a href="">Macbook Pro</a></h2>
                            <span class="quantity">数量: 1</span>
                            <span class="shp__price">￥13005.00</span>
                        </div>
                        <div class="remove__btn">
                            <a href="#" title="Remove this item"><i class="zmdi zmdi-close"></i></a>
                        </div>
                    </div>
                    <div class="shp__single__product">
                        <div class="shp__pro__thumb">
                            <a href="#">
                                <img src="assets/images/product/sm-img/2.jpg" alt="product images">
                            </a>
                        </div>
                        <div class="shp__pro__details">
                            <h2><a href="">华为手机</a></h2>
                            <span class="quantity">数量: 1</span>
                            <span class="shp__price">￥6500.00</span>
                        </div>
                        <div class="remove__btn">
                            <a href="#" title="Remove this item"><i class="zmdi zmdi-close"></i></a>
                        </div>
                    </div>
                </div>
                <ul class="shoping__total">
                    <li class="subtotal">总计:</li>
                    <li class="total__price">￥13000.00</li>
                </ul>
                <ul class="shopping__btn">
                    <li><a href="cart.html">查看购物车</a></li>
                </ul>
            </div>
        </div>
        <!-- End Cart Panel -->

<?php else: ?>
<!-- Start Cart Panel -->
        <div class="shopping__cart">
            <div class="shopping__cart__inner">
                <div class="offsetmenu__close__btn">
                    <a href="#"><i class="zmdi zmdi-close"></i></a>
                </div>
                <div class="shp__cart__wrap">
                        <?php 
                        if($r):
                        foreach ($array as $k ):
                                
                    ?>
                    <div class="shp__single__product">
                    
                        <div class="shp__pro__thumb">
                            <a href="#">
                                <img src="assets/uploads/default.jpeg" alt="product images">
                            </a>
                        </div>
                        <div class="shp__pro__details">
                            <h2><a href=""><?php echo $k['products']['name'];?></a></h2>
                            <span class="quantity">数量：<?php echo $k['quantity'];?></span>
                            <span class="shp__price"></span>
                        </div>
                        <div class="remove__btn">
                            <a href="#" title="Remove this item"><i class="zmdi zmdi-close"></i></a>
                        </div>

                    </div>
                   <?php endforeach;endif;?>
                </div>
                <ul class="shoping__total">
                    <li class="subtotal">总计:</li>
                    <li class="total__price"><?php echo $r['price'];?></li>
                </ul>
                <ul class="shopping__btn">
                    <li><a href="cart.php">查看购物车</a></li>
                    <li class="shp__checkout"><a href="pan_check.php">去结账</a></li>
                </ul>
            </div>
        </div>
        <!-- End Cart Panel -->
    <?php  endif; ?>